﻿using System;
using Microsoft.Xna.Framework;

namespace MyCraft.Minecraft_2D.Blocs
{
    class Leaves : Bloc
    {
        #region Attributs
        #endregion

        #region Constructeur
        public Leaves(double timer)
            : base(timer, 5)
        {
            _waitTime = new Random((int)timer).Next(5000, 7000);
            _light = -3;
            _minLight = 0;
            _id = 7;
            _name = "Leaves";
            _percent = 0;
            _color = Color.GreenYellow;
        }
        #endregion

        #region Proprietes
        #endregion

        #region Methodes
        public override TypeBloc OnNew(Block bloc)
        {
            foreach (Block b in Map.InRange(bloc.Position, 3, TypeBloc.Wood))
                return TypeBloc.Leaves;

            return TypeBloc.None;
        }

        public override Bloc Update(Block block, double timer)
        {
            if (timer > _startTimer + _waitTime)
            {
                //bool find = false;
                foreach (Block b in Map.InRange(block.Position, 3, TypeBloc.Wood))
                {
                    Refresh(timer, 5000, 7000);
                    return this;
                }
                return BlocSet.GetSingleton()._newBlocs[TypeBloc.Air].Invoke(new Vector2(0.5f), 0);
            }
            return this;
        }
        #endregion
    }
}
